/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package talkunix;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 *
 * @author Administrador
 */
public class DeamonOuvir implements Runnable {

    public  ServerSocket Deamon;
    public  Socket DeamonSocket = null;

    public DeamonOuvir(int porta) throws IOException {

        Deamon = new ServerSocket(porta);


    }
   

  

    public void run(){
        
        try {
            System.out.println("esperando conexão");
            DeamonSocket = Deamon.accept();

        } catch (IOException ex) {
            ClienteServidor.deuErro("Deu Erro!");
        }

        System.out.println("DemonSocket set");
        Secao.setgo();
        Secao.DeamonSocket= DeamonSocket;
        Secao.Deamon = Deamon;
        try {
            Secao.Abrir();

        } catch (IOException ex) {
            Logger.getLogger(DeamonOuvir.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InterruptedException ex) {
            Logger.getLogger(DeamonOuvir.class.getName()).log(Level.SEVERE, null, ex);
        }

        
//        Secao.setgo();
//        try {
//            Secao.Abrir();
//        } catch (IOException ex) {
//           ClienteServidor.deuErro("Deu Erro");
//        }
//        System.out.println(Secao.getgo());


    }


}
